﻿//-----------------------------------------------------------------------
// <copyright file="MessageBox.cs" company="Noboru Project">
//      Copyright (c) Noboru Project. All rights reserved.
//
//      This source code is subject to terms and conditions of the New BSD License (BSD).
//      A copy of the license can be found in the License.html file at the root of this 
//      distribution. If you can not locate the New BSD License (BSD), please send an 
//      email to noboru_adm@live.com.
//      By using this source code in any fashion, you are agreeing to be bound by
//      the terms of the New BSD License (BSD) for Noboru.
//
//      You must not remove this notice, or any other, from this software.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Noboru.Windows.Controls
{
    /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Class"]/*' />
    public class MessageBox
    {
        private bool _isBackgroundGrayed;
        private DialogResult _dialogResult;

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Constructor"]/*' />
        public MessageBox()
        {
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Closed"]/*' />
        public event EventHandler Closed;

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.DialogResult"]/*' />
        public DialogResult DialogResult
        {
            get
            {
                return this._dialogResult;
            }

            set
            {
                this._dialogResult = value;
            }
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.IsBackgroundGrayed"]/*' />
        public bool IsBackgroundGrayed
        {
            get
            {
                return this._isBackgroundGrayed;
            }

            set
            {
                this._isBackgroundGrayed = value;
            }
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Show"]/*' />
        public void Show(string text)
        {
            this.Show(text, "Message", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Show1"]/*' />
        public void Show(string text, string title)
        {
            this.Show(text, title, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Show2"]/*' />
        public void Show(string text, string title, MessageBoxButtons buttons)
        {
            this.Show(text, title, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Show3"]/*' />
        public void Show(string text, string title, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            this.Show(text, title, buttons, icon, MessageBoxDefaultButton.Button1);
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.Show4"]/*' />
        public void Show(string text, string title, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
        {
            MessageBoxControl messageBoxControl = new MessageBoxControl();

            messageBoxControl.Message = text;
            messageBoxControl.Title = title;
            messageBoxControl.MessageBoxButtons = buttons;
            messageBoxControl.MessageBoxIcon = icon;
            messageBoxControl.MessageBoxDefaultButton = defaultButton;

            messageBoxControl.Closed += new EventHandler(this.MessageBoxControl_Closed);

            messageBoxControl.ShowModal(this._isBackgroundGrayed);
        }

        /// <include file='Documentation\MessageBoxDocumentation.uex' path='Members/Member[@for="MessageBox.OnClosed"]/*' />
        protected virtual void OnClosed(EventArgs e)
        {
            if (this.Closed != null)
            {
                this.Closed(this, e);
            }
        }

        private void MessageBoxControl_Closed(object sender, EventArgs e)
        {
            this._dialogResult = ((MessageBoxControl)sender).DialogResult;

            this.OnClosed(new EventArgs());
        }
    }
}
